package com.holly.unit.deform.designer.core.table;

import com.holly.unit.deform.designer.kit.DbTableKit;
import com.holly.unit.deform.designer.pojo.dto.CreateTableDTO;

import java.sql.SQLException;
import java.util.List;

/**
 * 类描述: 基于Mybatis实现数据定义语言DDL
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/7/23 10:30
 */
public class DbTableDDLManager {

    private IDbTableDDL dbTableDDL;


    private DbTableDDLManager(IDbTableDDL dbTableDDL) throws SQLException {
        this.dbTableDDL = DbTableKit.getDbTableDDL();
    }

    // 创建表
    public void createTable(CreateTableDTO createTableDTO) {
        String ddl = dbTableDDL.createTable(createTableDTO);
        DdlExecutor.execute(ddl);
    }
    // 修改表
    public void alertTable(CreateTableDTO createTableDTO) {
        List<String> ddls = dbTableDDL.alertTable(createTableDTO);
        for (String ddl:ddls) {
            DdlExecutor.execute(ddl);
        }
    }
}
